﻿@using System.Text;
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Admin/Views/Shared/NoLayout.cshtml";
}
@functions{
    void CreateSubTree(DirectoryInfo info, StringBuilder builder)
    {
        var children = info.GetDirectories();
        if (children.Count() > 0)
        {
            builder.Append("<ul>");
            foreach (var item in children)
            {
                builder.AppendFormat("<li><a href='#'>{0}</a>", item.Name);
                CreateSubTree(item, builder);
                builder.Append("</li>");
            }
            builder.Append("</ul>");
        }
    }
}
@{
    
    var builder = new StringBuilder();
    foreach (var item in ViewBag.DirectoryInfo.GetDirectories())
    {
        builder.AppendFormat("<li><a href='#'>{0}</a>", item.Name);
        CreateSubTree(item, builder);
        builder.Append("</li>");
    }
}
<div class="toolbar">
    <a href="#" class="button">Create Folder</a>
    @Html.ActionLink("Upload Image", "Upload", "Image", new { @class = "button" })
</div>
<div class="file-path">
    <input type="text" readonly="readonly" />
</div>
<div id="main">
    <div class="left">
        <ul id="tree-menu" class="treeview-default">
            <li><a href="#" class="root">@("Root".Localize())</a>
                <ul>
                    @Html.Raw(builder.ToString())
                </ul>
            </li>
        </ul>
    </div>
    <div class="right">
    </div>
    <div class="clearfix">
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $('#tree-menu').treeview({
            animated: 'fast',
            collapsed: false,
            unique: true,
            persist: 'cookie'
        });
    });
</script>
